﻿using brevis.Nop.SDK;
using brevis.Nop.SDK.Entity;
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;

namespace brevis.Nop.SDK.ReportDataGetter
{
    /// <summary>
    /// Represents a getter for HttpContxt QueryString parameter
    /// </summary>
    public class HttpContextQueryString : IReportDataGetter
    {
        /// <summary>
        /// Not implemented ...
        /// </summary>
        /// <returns></returns>
        public object Get()
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Gets a vlaue form a QueryString Parameter
        /// </summary>
        /// <param name="param">QueryString Parameter Key</param>
        /// <returns></returns>
        public object Get(MethodAttribute[] param)
        {
            var key = (param[0].Value);

            var ret = HttpContext.Current.Request.QueryString[key];

            if (ret == null)
                throw new Exception(
                    string.Format(
                        "HttpContext.Current.Request.QueryString[{0}] not found!\n" +
                            "Please check URL or NopReport-Configuration.", 
                        key));

            return ret.ToString();
        }
    }
}
